<?php
session_start();
error_reporting(0);
if(  isset ( $_POST['offset'] ) && isset ( $_POST['number'] ) ) {
 if ( isset ( $_SESSION['authenticated'] ) ) {
   if( isset( $_POST ) && $_SERVER['REQUEST_METHOD'] == "POST" ) {

   	/*
	 * ---------------------------------------
	 *   Valid $offset && Valid $postnumbers
	 * ---------------------------------------
	 */
	$offset                 = is_numeric($_POST['offset']) ? $_POST['offset'] : die();
	$postnumbers            = is_numeric($_POST['number']) ? $_POST['number'] : die();


	/*
	 * ---------------------------------------
	 *   Query > ID || Query < ID
	 * ---------------------------------------
	 */
	if( $_POST['query'] == 1 ) {
		$query = '<';
	} else {
		$query = '>';
	}

	/*
	 * --------------------------
	 *   Require/Include Files
	 * -------------------------
	 */
	require_once('../../class_ajax_request/classAjax.php');
	include_once('../../application/functions.php');
	include_once('../../application/DataConfig.php');

	/*
	 * ----------------------
	 *   Instance Class
	 * ----------------------
	 */
	$obj         = new AjaxRequest();
	$infoUser    = $obj->infoUserLive( $_SESSION['authenticated'] );

	$response    = $obj->getInteractions('
	U.status = "active" && I.id '.$query.' '.$offset .'
	',
	'LIMIT '.$postnumbers,
	$_SESSION['authenticated']
	);
//    echo '<pre>';
//       print_r($response);
//       echo '</pre>';
	$countPosts = count( $response );
   		 if( $countPosts != 0 ) :
			 foreach ( $response as $key ) {


				$_idUser = $key['user_id'];

				//============ VERIFIED
				if( $key['type_account'] == '1' ) {
					$verified = ' <img class="verified_img" src="'.URL_BASE.'public/img/verified_min.png">';
				} else {
					$verified = null;
				}

				switch( $key['type'] ) {
					case 1:
						$action          = $_SESSION['LANG']['followed_you'];
						$icoDefault      = 'follow';
						$linkDestination = false;
						$idTag           = null;
						break;
					case 2:
						$action          = $_SESSION['LANG']['reposted_post'];
						$icoDefault      = 'reposted';
						$reply           = null;
						$linkDestination = true;
						$idTag           = null;
						break;
					case 3:
						$action          = $_SESSION['LANG']['favorited_post'];
						$icoDefault      = 'favorite';
						$linkDestination = true;
						$idTag           = null;
						break;
					case 4:
						$action          = $_SESSION['LANG']['commented_post'];
						$icoDefault      = 'reply';
						$linkDestination = true;
						$idTag           = '#reply-status-wrap';
						break;
					case 5:
						$action          = '<strong style="color: #333; font-weight: bold;">@</strong>'.$_SESSION['LANG']['mentions'].'';
						$icoDefault      = null;
						$linkDestination = true;
						$idTag           = null;
						break;
					case 6:
						$action          = '<strong style="color: #FF7000; font-weight: bold;">@</strong>'.$_SESSION['LANG']['mentions_in_replies'].'';
						$icoDefault      = null;
						$linkDestination = true;
						$idTag           = '#reply-status-wrap';
						break;
				}

				/* Url */
				$urlStatus = URL_BASE.$key['p_username'].'/status/'.$key['id'];

                 $idPost = $key['id'];
                 $post_meta_array = $obj->get_post_meta($idPost);
                 $getMedia       = $obj->getMedia( $idPost, $token_id );
                 $votersCount = count($obj->getVoter($idPost));
//                 echo '<pre>';
//                 print_r($getMedia);
//                 echo '</pre>';
                 $count_answer = $obj->gettanswerCount($idPost);
                 $countFavorite = $obj->favoriteCount($idPost);
                 $countReply = $obj->countReply($idPost);
                 $userInfoCus = $obj->infoUserLive($_SESSION['authenticated']);

				?>
				<!-- POSTS -->

                 <!-- POSTS -->

                 <li id="post-li-<?php  echo $key['id'] ?>" class="hoverList lato  getData " data-expand="<?php echo $_SESSION['LANG']['expand']; ?>" data-hide="<?php echo $_SESSION['LANG']['hide']; ?>" class="" data="<?php echo $key['id']; ?>" data-token="<?php echo $key['token_id']; ?>" data="<?php echo $idPost; ?>" xmlns="http://www.w3.org/1999/html">
                     <div class="loading-answer"></div>
	<span class="paddingPost">
		<div class="li-header">
            <?php echo $spanAbsolute; ?>
            <a  href="<?php echo URL_BASE.$key['username']; ?>" data-id="<?php echo $_idUser ?>" class="openModal">
                <?php
                $avatar = $key['avatar'];
                $avatar = _Function::checkExistsAvatar($avatar,'48-48');

                ?>
                <img class="avatar_user" src="<?php echo $avatar ?>">
            </a>
	<span class="detail_grid">
		<span class="timestamp timeAgo" data="<?php echo date('c', strtotime( $key['date'] ) ); ?>"></span>
<!--		<a  href="--><?php //echo URL_BASE.$key['username']; ?><!--" data-id="--><?php //echo $_idUser ?><!--" class="username openModal">--><?php //echo stripslashes( $key['name'] ).$verified; ?><!-- </a> <strong class="usernameClass">@--><?php //echo $key['username']; ?><!--</strong>-->



        <p class="postTitle">
            <?php
            /*<------- * POST DETAILS * -------->*/
            echo _Function::checkText( $key['post_details'] ); ?>
            <!-- media -->


            <!--end media -->

        </p>

        </div>



        <?php
        if( $key['repost_of_id'] != 0 ) {

            ?>
            <p style="font-size: 13px; color: #999; font-style: italic;">
                <img style="vertical-align: middle;" src="<?php echo URL_BASE; ?>public/img/repost-ico.png" /> <?php echo $_SESSION['LANG']['reposted_by']; ?> <?php echo $nameUser; ?>
            </p>
        <?php } ?>

        <!-- EXPAND -->
		<!--	<a  data-expand="<?php echo $_SESSION['LANG']['expand']; ?>" data-hide="<?php echo $_SESSION['LANG']['hide']; ?>" class="expand getData" data="<?php echo $key['id']; ?>" data-token="<?php echo $key['token_id']; ?>">
				<?php echo $icon; ?>
				<span class="textEx"><?php echo $_SESSION['LANG']['expand']; ?></span> <?php echo $typeMedia; ?>
			</a>

			<!-- FAVORITES -->
        <?php if( isset( $_SESSION['authenticated'] ) ): ?>
        <!--	<a data-fav="<?php echo $_SESSION['LANG']['favorite']; ?>" data-fav-active="<?php echo $_SESSION['LANG']['favorited']; ?>" class="favorite favoriteIcon" data="<?php echo $key['id']; ?>" data-token="<?php echo $key['token_id']; ?>">
				<i class="favorite_ico icons<?php echo $iconFav; ?>"></i>
				<span<?php echo $spanFav; ?>><?php echo $textFav; ?></span>
			</a>
			<?php endif; ?>
			<!-- REPOST -->
        <?php if( isset( $_SESSION['authenticated'] ) && $key['user'] !=  $_SESSION['authenticated'] ): ?>
        <!--	<a data-rep="<?php echo $_SESSION['LANG']['repost']; ?>" data-rep-active="<?php echo $_SESSION['LANG']['reposted']; ?>" class="repost_button repostIcon" data="<?php echo $key['id']; ?>" data-token="<?php echo $key['token_id']; ?>">
				<i class="repost_ico icons <?php echo $iconRepost; ?>"></i>
				<span<?php echo $spanRepost; ?>><?php echo $textRepost; ?></span>
			</a>
			<?php endif; ?>
			<!-- TRASH -->
        <?php if( $key['user'] == $_SESSION['authenticated'] ): ?>
            <!--	<a data-message="<?php echo $_SESSION['LANG']['delete_post']; ?>" data-confirm="<?php echo $_SESSION['LANG']['confirm']; ?>" class="trash" data-image="<?php echo $key['photo']; ?>" data="<?php echo $key['id']; ?>" data-token="<?php echo $key['token_id']; ?>">
				<i class="trash_ico icons"></i>
				<span><?php echo $_SESSION['LANG']['trash']; ?></span>
			</a>   -->
        <?php endif; ?>

        <!-- details-post -->
	<span class="details-post">
	</span><!-- details_post -->
        <?php if( isset( $_SESSION['authenticated'] ) ): ?>
            <!-- Grid Reply -->
            <div class="grid-reply <?php echo $key['id'] ?>" style="display: none;">

                <?php

                if($getMedia[0]['photo']!=''){
                    $urlStatus = URL_BASE.'/thumb/300-300-upload/'.$getMedia[0]['photo'];
                    $urlOriginal =  URL_BASE.'upload/'.$getMedia[0]['photo'];
                    //echo $urlStatus;
                    echo '
                    <a data-view="Details →" data-url="'.$urlDataStatus.'" class="galeryAjax cboxElement" href="'.$urlOriginal.'">
                        <span class="container-media-1">
                        <img style="margin-top:10px" class="photoPost" src="'.$urlStatus.'">
                        </span>
                    </a>
                    ';
                    $urlDataStatus  = $urlStatus = URL_BASE.$getMedia[0]['username'].'/status/'.$getMedia[0]['id'];
                }

                ?>

                <div id="post-replay-<?php echo $key['id'] ?>" class="chart">
                    <div class="chart-content">
                        <?php include('answer.content.php'); ?>
                    </div>

                </div>

                <ul class="actions_content">
                    <li id="chat" class="<?php echo $key['id'] ?>">
                        <form action="" method="post" accept-charset="UTF-8" id="form_reply_post">
                            <input type="hidden" name="id_reply" id="id_reply" value="<?php echo $key['id']; ?>">
                            <input type="hidden" name="token_reply" id="token_reply" value="<?php echo $key['token_id']; ?>">
                            <textarea name="reply_post" id="reply_post"></textarea>
                            <div class="counter"></div>
                            <button id="button_reply" disabled="disabled" style="opacity: 0.5; cursor: default;" type="submit"><?php echo $_SESSION['LANG']['reply']; ?></button>
                        </form>
                        <div class="chat-here">

                        </div>
                    </li>
                    <li id="stat">

                    </li>
                    <li id="voter">

                    </li>
                </ul>
                <?php
                $postId = $key['id'];
                $userId = $key['user_id']; //user create

                include('bottomtoolbox.php');
                '' ;
                ?>
                <div class=" share_this share-<?=$postId?>" style="float: right;display: none">
                    <a href="http://www.facebook.com/sharer/sharer.php?s=100&p[url]=<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/'.$key['username'].'/status/'.$postId; ?>" target="_blank">
                  <span style="background-image: url(http://w.sharethis.com/images/facebook_32.png);display: inline-block;
height: 32px;width: 32px;position: relative;"></span>
                    </a>
                    <a href="https://twitter.com/home?status=<?='http://'.$_SERVER['HTTP_HOST'].'/'.$key['username'].'/status/'.$postId ?>" target="_blank">
                        <span style="background-image: url(http://w.sharethis.com/images/twitter_32.png);display: inline-block;height: 32px;width: 32px;position: relative;"></span>
                    </a>
                </div>





            </div><!-- Grid Reply -->

        <?php endif; ?>
  </span><!-- paddingPost  -->
                     </span>
                     <ul class="actions" data-type-account="<?php echo $userInfoCus->type_account ?>" >
                         <li data-rel="stat" class="stat"></li>
                         <li>
                             <a href="<?php echo URL_BASE.$key['username']; ?>"  class="favorite favoriteIcon grey post_action" style="padding-top: 4px">
                                 <span class="comment_span grey captital">@<?php echo $key['username']; ?> </span>
                             </a>
                         </li>
                         <li data-rel="chat" >
                             <div class="getData" data="<?php echo $key['id']; ?>" data-token="<?php echo $key['token_id']; ?>">
                                 <span class="comment_span grey countreply ">with <?= $countReply[0]['countReply'] ?></span>
                                 <i class="comment_ico"></i>
                             </div>
                         </li>
                         <li data-rel="voter">
                             <span class="comment_span grey countvote">and <?php echo $votersCount; ?></span>
                             <i class="handle_ico"></i>
                         </li>
                     </ul>

                 </li>


             <?php }  endif;
     }//<-- SESSION
  }//<-- if token id
}//<-- ISSET
?>